var App = (function () {

    return {
    	createGrid: function(config) {
    		var table = '<table class="table table-bordered">';
    		
    		var header = '<thead><tr>';
    		var i = 0;
    		for (i = 0; i < config.colums.length; i++) {
    			header += '<th>' + config.columns[i] + '</th>';
    		}
    		header += '</tr></thead>';
    		table += header;
    		
    		
    		var body = '<tbody>';
    		var j = 0;
    		for (i = 0; i < data.length; i++) {
    			var record = data[i];
    			
    			
    			for (j = 0; j < record.length; j++) {
    				
    				
    			}
    			
    			
    		}
    		
    		
    		// rekordy kazyd rekord ma column.length wartosci
    		// data : [ [1,2,3,4,5 ],  ]
    		
    		
    		table += '</tbody></table>';
    		return table;
    	},
        executeServerAction: function (config) {
            $.ajax({
                type: config.type,
                url: config.url,
                data: config.params,
                success: function (data, status, jqXHR) {
                    config.onSuccessFn(data, status, jqXHR);
                },
                error: function (jqXHR, status, errorThrown) {
                    alert('Error, Status: ' + status);
                }
            });
        },
        createAddEditWindow: function (config) {
            App.executeServerAction({
                type: 'GET',
                url: config.url,
                params: config.params,
                onSuccessFn: function (data, status, jqXHR) {
                    var windowContent = jqXHR.responseText;
                    $('<div>' + windowContent + '</div>').dialog({
                        title: config.title,
                        width: config.width,
                        height: config.height,
                        buttons: {
                            'Zapisz': function () {
                                config.onSave();
                            },
                            'Anuluj': function () {
                                $(this).dialog('close');
                            }
                        }
                    });
                }
            });
        },
        showMessage: function (title, text) {
            $('<div>' + text + '</div>').dialog({
                title: title,
                buttons: {
                    'Zamknij': function () {
                        $(this).dialog('close');
                    }
                }
            })
        },
        showConfirmWindow: function (config) {
            $('<div>' + config.body + '</div>').dialog({
                title: config.title,
                width: config.width,
                height: config.height,
                buttons: {
                    'Tak': function () {
                        config.onConfirm();
                    },
                    'Nie': function () {
                        $(this).dialog('close');
                    }
                }
            });
        }
    }
}());